package com.xinqing.test.collection.map;

import com.alibaba.fastjson.JSON;
import com.xinqing.test.modle.Age;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author:CHQ
 * @Date:2020/12/30 14:28
 * @Description
 */
public class ComputeIfAbsent {
    public static void main(String args[]) {


        HashMap<Integer, List<Age>> map = new HashMap<>();

        //主要目的是拿到一个value的对象，进行后续操作
        List<Age> ages = map.computeIfAbsent(1, k -> new ArrayList<>());

        Age age = new Age("18");
        ages.add(age);

        System.out.println(JSON.toJSONString(map));
    }
}
